package com.zhutengwei.android.zuji.tool;

import android.content.Context;
import android.content.SharedPreferences;

import com.zhutengwei.android.zuji.db.TableDao;
import com.zhutengwei.android.zuji.model.UserModel;

/**
 * Created by Administrator on 2017/2/3.
 */
public class IsLogined {

    private static TableDao dao;
    /**
     * 通过获取sharepreferences来判断是否登录，如果登录，返回UserModel
     * @return
     */
    public static boolean isLogined(Context context,
                                      final String TAG,
                                      final String EMAIL){
        SharedPreferences sp = context.getSharedPreferences(TAG,Context.MODE_PRIVATE);
        String email = sp.getString(EMAIL,null);
        if(email == null){
            return false;
        }
        return true;
    }
    /**
     * 通过获取sharepreferences来判断是否登录，如果登录，返回UserModel
     * @return
     */
    public static UserModel isLoginedAndGetUser(Context context,
                                      final String TAG,
                                      final String EMAIL){
        SharedPreferences sp = context.getSharedPreferences(TAG,Context.MODE_PRIVATE);
        String email = sp.getString(EMAIL,null);
        UserModel user;
        dao = new TableDao(context);
        user = dao.getUserByEmail(email);
        return user;
    }
}
